﻿using System.Data;
using OVS.CoreDomain;
using OVS.CoreDomain.Data;
using System.Collections.Generic;
using System;



namespace OVS.Data
{
    public class DalLogin : Dal<ILoggedin, Loggedin>, IDalLogin
    {

        private const string SP_LOGIN = "usp_Login";

        
         private readonly IDalManager _manager;
        private static readonly IDalLogin _instance = new DalLogin();

        public static IDalLogin Instance
        {
            get { return _instance; }
        }

        public DalLogin()
        {
            _manager = new DalManager();
        }

        public DalLogin(IDalManager manager)
        {
            _manager = manager;
        }

        protected override void Convert(ILoggedin obj, DataRow row)
        {
            obj.LoggedIn = _manager.GetValue<bool>(row, "LoggedIn");


        }


        #region IDalLogin Members

        public ILoggedin Login(string voterId, string password, bool isAdmin)
        {
            _manager.StoredProcedureName = SP_LOGIN;
            _manager.AddInParameter("@VoterId", DbType.String, voterId);
            _manager.AddInParameter("@Password", DbType.String, password);
            _manager.AddInParameter("@Admin", DbType.Boolean, isAdmin);


            ILoggedin loggedIn =Convert( _manager.ExecuteDataSet());
            return loggedIn;
        
        }

        #endregion
    }
}
